package com.example.sys.ai.controller;

import com.example.core.utils.Result;
import com.example.sys.ai.dto.IDCard;
import com.example.sys.ai.service.SysAiService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
public class SysAiController {

    @Resource
    private SysAiService sysAiService;

    /***
     * 身份证正面识别
     * @param file
     * @return
     */
    @ResponseBody
    @PostMapping(value = "idCardFront")
    public Result idCardFront(MultipartFile file) {
        try {
            IDCard.Front idCardFront = this.sysAiService.idCardFront(file.getBytes());
            return Result.success(idCardFront);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    /***
     * 身份证反面识别并返回
     * @param file
     * @return
     */
    @ResponseBody
    @PostMapping(value = "idCardBack")
    public Result idCardBack(MultipartFile file) {
        try {
            IDCard.Back idCardBack = this.sysAiService.idCardBack(file.getBytes());
            return Result.success(idCardBack);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }
}
